/*
 * JGO2RDF creates a RDF representation of GAF2 files, which are automatically sourced from GO ftp site.
 * Copyright (C) 2012 Matthew M. Hindle & Artem Lysenko
 *
 * This program is free software: you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation, either version 3 of the License, or
 * (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program.  If not, see <http://www.gnu.org/licenses/>.
 */

package uk.co.jgo2rdf.goa.go;

import java.util.HashMap;
import java.util.Map;

/**
 * Represents an aspect of the Gene Ontology
 * User: hindlem
 * Date: 4/11/11
 * Time: 2:31 PM
 */
public enum OntologyType {

    GOProcess("biological process"), GOFunction("molecular function"), GOComponent("cellular component");

    OntologyType(String name) {
        this.name = name;
    }

    private final String name;

    public String getName() {
        return name;
    }

    private final static Map<String, OntologyType> map;

    static {
        map = new HashMap<String, OntologyType>();
        map.put("biological process", OntologyType.GOProcess);
        map.put("molecular function", OntologyType.GOFunction);
        map.put("cellular component", OntologyType.GOComponent);
        map.put("go biological process", OntologyType.GOProcess);
        map.put("go molecular function", OntologyType.GOFunction);
        map.put("go cellular component", OntologyType.GOComponent);
        map.put("process", OntologyType.GOProcess);
        map.put("function", OntologyType.GOFunction);
        map.put("component", OntologyType.GOComponent);
        map.put("p", OntologyType.GOProcess);
        map.put("f", OntologyType.GOFunction);
        map.put("c", OntologyType.GOComponent);
        map.put("bp", OntologyType.GOProcess);
        map.put("mf", OntologyType.GOFunction);
        map.put("cc", OntologyType.GOComponent);
    }

    public static OntologyType getOntology(String name) throws UnknownOntologyNameException {
        OntologyType ontology = map.get(name.toLowerCase().replaceAll("_", " "));
        if (ontology != null) {
            return ontology;
        } else {
            throw new UnknownOntologyNameException(name);
        }
    }

    public static class UnknownOntologyNameException extends Exception {
        public UnknownOntologyNameException(String message) {
            super(message);
        }
    }

}
